package com.sylli.oeuf.server.game.logic.skill;

import java.util.ArrayList;
import java.util.Collection;

import com.sylli.oeuf.server.game.logic.ActionProduct;
import com.sylli.oeuf.server.game.logic.BattleActor;
import com.sylli.oeuf.server.game.logic.CastingTarget;
import com.sylli.oeuf.server.game.logic.EventParameter;
import com.sylli.oeuf.server.game.logic.Skill;
import com.sylli.oeuf.server.game.logic.action.CombatLog;
import com.sylli.oeuf.server.game.logic.action.ConsumeMana;
import com.sylli.oeuf.server.game.logic.action.Damage;
import com.sylli.oeuf.server.game.logic.action.Healing;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueElement;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueFlag;
import com.sylli.oeuf.server.game.logic.invocation.EnoughMPInvocationCondition;
import com.sylli.oeuf.server.game.logic.invocation.InvocationAction;
import com.sylli.oeuf.server.game.logic.invocation.InvocationCondition;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEntry;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEvent;

public class Vampire_Drain extends Skill {
	public Vampire_Drain() {
		super("drain", CastingTarget.FocusTarget);
		this.getEntries().put(
				InvocationEvent.STD_IE_ON_ACTIVE,
				new InvocationEntry(
						new EnoughMPInvocationCondition() {

							@Override
							public int getAgainstValue(int rank) {
								return computeManaUse(rank);
							}
							
						},
						new InvocationAction() {
							@Override
							public Collection<ActionProduct> act(
									int rank, BattleActor caster,
									CastingTarget target,
									 EventParameter ep) {
								
								// caster deal damage to target
								// caster gain amount of HP corresponding to damage dealt
								// percentage of HP gained can be calculated by 10% + ((rank - 1) * 5%);
								// Ex.	rank1 = gain 10% of damage dealt
								//		rank2 = gain 15% of damage dealt
								//		rank3 = gain 20% of damage dealt
								int doDamage = (int) (Math.random() * (caster.getMaxDmg() - caster.getMinDmg())) + caster.getMinDmg();
								double drainFactor = 0.1 + ((rank - 1) * 0.05);
								int drain = (int) (doDamage * drainFactor);
								
								Collection<ActionProduct> product = new ArrayList<ActionProduct>();
								Damage damageProduct = new Damage(caster, 
										caster.getProperTarget(CastingTarget.FocusTarget),
										doDamage,
										ActionValueFlag.Normal,
										ActionValueElement.Shadow);
								product.add(damageProduct);
								Healing healProduct = new Healing(caster, 
										caster,
										drain,
										ActionValueFlag.Normal,
										ActionValueElement.Shadow);
								product.add(healProduct);
								product.add(new ConsumeMana(caster, 
										caster.getProperTarget(CastingTarget.FocusTarget),
										computeManaUse(rank)));
								product.add(new CombatLog(caster, caster.getProperTarget(CastingTarget.FocusTarget),
										caster.getName() + " bite " + caster.getProperTarget(CastingTarget.FocusTarget).getName() + " for %p and [" + name + "] %p.", 
										damageProduct, 
										healProduct));
								return product;
							}
						}));
	}
	
	private int computeManaUse(int rank) {
		return 8;
	}

}